import rclpy
from rclpy.node import Node

class TopicInfoNode(Node):
    def __init__(self):
        super().__init__('topic_info_node')

    def get_topic_list(self):
        topic_names_and_types = self.get_topic_names_and_types()
        for topic_name, topic_types in topic_names_and_types:
            self.get_logger().info(f'Topic: {topic_name}, Types: {topic_types}')

    def get_topic_type(self, topic_name):
        topic_names_and_types = self.get_topic_names_and_types()
        for name, types in topic_names_and_types:
            if name == topic_name:
                self.get_logger().info(f'Topic: {topic_name}, Type: {types[0]}')
                return
        self.get_logger().info(f'Topic {topic_name} not found')

def main(args=None):
    rclpy.init(args=args)
    node = TopicInfoNode()
    node.get_topic_list()
    node.get_topic_type('/topic_name')  # 替换为实际的topic名称
    rclpy.shutdown()

if __name__ == '__main__':
    main()